extends ../layout
include ../mixin/form-group
block content
  .wp-left
    .panel
      .panel-hd 用户登录
      .panel-bd.register
        form.form.form-horizontal(action="/user/login" method="POST")
          #passAlert.alert.alert-error.hide
          +form-group('text', '用户名', 'username', null, true)
          +form-group('password', '密　码', 'password', null, true)
          +form-btn('primary','submit', 'btn', '登录')
            
block script
  script
    :uglify
      $(function () {
        var username = $('#username');
        var password = $('#password');
        var error = $('#passAlert');
        var btn = $('#btn');
        $('form').submit(function (event) {
          event.preventDefault();
          var user = $.trim(username.val());
          var userlen = user.length;
          if(userlen == 0){
            error.text('用户名不能为空').show();
            return false;
          }
          var pass = $.trim(password.val());
          var passlen = pass.length;
          if(passlen == 0){
            error.text('密码不能为空').show();
            return false;          
          }
          
          btn.attr('disabled', true);
          $.ajax({
            url: '/user/login',
            type: 'POST',
            dataType: 'json',
            data:  {
              password: pass,
              username: user
            },
            complete: function () {
              btn.attr('disabled', false);
            },
            success: function (data) {
              if(data.status != 0)
                error.text(data.message).show();
              else 
                location.href = '/';
            }
          });
          
        });
      });
    
          
  
